package cl.ccs.migracionbcmc.util;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class TextLog {
    public final static TextLog INSTANCE = new TextLog();
        
    private TextLog() {
        super();
    }
    
    public static TextLog getInstance(){
        return INSTANCE;
    }
    
    public Result writeln(String fileName, String text) {
        text += StringUtil.NEWLINE;
        return write(fileName, text);
    }
    
    public synchronized Result write(String fileName, String text) {
        PrintWriter out;
        FileWriter fw;
        Result result = new Result();
        boolean append = true;
        try {
            fw = new FileWriter(fileName, append);
            out = new PrintWriter(fw);
            out.write(text);
            out.close();
            fw.close();
        } catch (IOException e) {
            result.addException(e);
        }
        
        return result;
    }
    
}
